package com.mjw.zstu.controller;

import com.mjw.zstu.VO.ExhibitionCompanyVO;
import com.mjw.zstu.entity.Exhibition;
import com.mjw.zstu.entity.Type;
import com.mjw.zstu.mapper.ExhibitorMapper;
import com.mjw.zstu.resultDto.JsonResult;
import com.mjw.zstu.service.ExhibitionService;
import com.mjw.zstu.service.ExhibitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("exhibition")
public class ExhibitionController {
    @Autowired
    ExhibitionService exhibitionService;
    @Autowired
    ExhibitorService exhibitorService;
    @PostMapping("create")
    public JsonResult create(@RequestBody Exhibition exhibition){
        return exhibitionService.startExhibition(exhibition);
    }
//    @GetMapping("detail")
//    public JsonResult getDetail(@RequestParam int id){
//        return new JsonResult(200,"获取成功",exhibitionService.getDetail(id));
//    }
    @RequestMapping("type")
    public JsonResult<List<Type>> getTypeList(){
        return new JsonResult(200,"获取成功", exhibitionService.getTypes());
    }
    @RequestMapping("list")
    public JsonResult list(int pageNum,int pageSize){
        return exhibitionService.getexhibition((pageNum-1)*pageSize,pageSize);
    }
    @RequestMapping("refuse")
    public JsonResult refuse(@RequestBody Exhibition exhibition){
      return  exhibitionService.refuse(exhibition);
    }
    @RequestMapping("review")
    public JsonResult review(@RequestParam int id){
        Exhibition exhibition=new Exhibition();
        exhibition.setId(id);
        exhibition.setIs_review(1);
        int success=exhibitionService.reviewExhibiton(exhibition);
        if(success==1){
            return new JsonResult(200,"审核成功",null);
        }
        return new JsonResult(500,"审核失败",null);
    }
    @RequestMapping("delete")
    public JsonResult deleteExhibition(int id){
        return exhibitionService.deleteExhibition(id);
    }
    @RequestMapping("companyid")
    public JsonResult getExhibitionbyId(@RequestParam int company_id){
        return exhibitionService.getexhibitionbyCompanyID(company_id);
    }
    @RequestMapping("typeid")
    public JsonResult getExhibitionbyTypeid(@RequestParam int type_id,int pageSize,int pageNum){
        return exhibitionService.getexhibitionbytype(type_id,pageNum,pageSize);
    }
    @RequestMapping("detail")
    public JsonResult getExhibitionByid(@RequestParam int id){
        return exhibitionService.getExhibitionByid(id);
    }
    @PostMapping("update")
    public JsonResult updateExhibition(@RequestBody Exhibition exhibition){
        return exhibitionService.updateExhibition(exhibition);
    }
    @RequestMapping("today")
    public JsonResult getTodayExhibition(){
        return exhibitionService.getTodayExhibition();
    }
    @RequestMapping("companyexhibition")
    public JsonResult getCompanyExhibiton(@RequestParam int company_id){
        return exhibitionService.CompanyExhibiton(company_id);
    }
}
